package controleur;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import vue.PanelChoice;
import vue.VueEditeurCK;

import modele.CKModel;
import modele.Concept;
import modele.Knowledge;
import modele.TreeLayout;

public class ControleAddConcept implements ActionListener {

	CKModel<String, String> _modele;
	VueEditeurCK _vue;
	
	public ControleAddConcept(CKModel<String, String> modele, VueEditeurCK vue){
		_modele = modele;
		_vue = vue;
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		
		Concept<String> child = new Concept<String>(_modele.getCSize(), _vue.getPanelPart().getTxtChild());
		_modele.partition(child, _modele.findConceptFromId(_vue.getPanelPart().getCmbFather().getSelectedIndex()));
		
		if(_vue.getPanelPart().getRdbOld().isSelected()){

			_modele.addLink(child, _modele.getKSpace().elementAt(_vue.getPanelPart().getCmbOldK().getSelectedIndex()));
			System.out.println(child);
			System.out.println(_modele.getKSpace().elementAt(_vue.getPanelPart().getCmbOldK().getSelectedIndex()));
		} else if(_vue.getPanelPart().getRdbNew().isSelected()) {
			
			Knowledge<String> knowledge = new Knowledge<String>(_modele.getKSpace().size(), _vue.getPanelPart().getTxtNewK());
			_modele.addKnowledge(knowledge);
			_modele.addLink(child, knowledge);
			
		}
		
		_vue.getPanelPart().LoadConcept();
		_vue.getPanelPart().LoadKnowledge();
		
		TreeLayout tl = new TreeLayout(_modele);
		tl.buildTree();
		
		_vue.getEditorFrame().remove(_vue.getPanelPart());
		_vue.getEditorFrame().add(_vue.getPanelC(), BorderLayout.NORTH);
		
		
		_vue.getEditorFrame().paint(_vue.getEditorFrame().getGraphics());
		_vue.dessiner();
		
		
		
	}

	
	
}
